<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>{{.siteName}}</title>
    {{if .zTree}}
        <link rel="stylesheet" href="/static/zTree3/css/demo.css?t=5" type="text/css">
        <link rel="stylesheet" href="/static/zTree3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    {{end}}
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/admin/css/app.css?t=2">
    <link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css" media="all">
</head>

<style>
    .modal-hide{
        display: none;
    }
</style>
<body>
<!-- 公共头部  start-->
<div class="nav-title {{if .hideTop}} modal-hide {{end}}">
    <div class="tl fl">
        <i class="fa fa-clock-o fa-spin" style="font-size: 18px;" aria-hidden="true"></i>
    {{.pageTitle}}
    </div>
    <div class="tr fr">
        <button class="layui-btn layui-btn-radius layui-btn-primary layui-btn-xs" onclick="javascript:window.location.reload();"><i class="fa fa-refresh" aria-hidden="true" id="reload"></i></button>
    </div>
</div>
<!-- 公共头部 end-->
<script src="/static/layui/layui.js"></script>


<style>
    .layui-form-item{
        margin-bottom: 0px;
    }
    legend{
        font-size: 14px !important;
        color: #009688;
        font-weight: bold !important;
    }
</style>
<div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
    <!--<div class="layui-btn-container mw200">
        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="edit">编辑任务</button>
        <button lay-submit class="layui-btn  layui-btn-sm layui-btn-primary" lay-filter="del">删除任务</button>
    </div>-->

    <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;padding-right: 10px;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>任务 {{.detail.id}} 详情</legend>
        </fieldset>
        <table class="layui-table" lay-skin="nob" lay-size="sm">
            <colgroup>
                <col width="80">
                <col width="400">
                <col>
            </colgroup>

            <tbody>

            <tr>
                <td>jobId</td>
                <td>{{.detail.id}}</td>
                <td></td>
            </tr>
            <tr>
                <td>jobKey</td>
                <td>{{.detail.job_key}}</td>
                <td></td>
            </tr>

            <tr>
                <td>主题</td>
                <td>{{.detail.topic}}</td>
                <td></td>
            </tr>

            <tr>
                <td>状态</td>
                {{if eq .detail.status "0"}}
                <td><span class="layui-badge layui-bg-orange">delay</span></td>
                {{else if eq .detail.status "1"}}
                <td><span class="layui-badge layui-bg-cyan">ready</span></td>
                {{else if eq .detail.status "2"}}
                <td><span class="layui-badge layui-bg-blue">reserved</span></td>
                {{else if eq .detail.status "2"}}
                <td><span class="layui-badge layui-bg-green">delete</span></td>                
                {{end}}
                <td></td>
            </tr>
            
            <tr>
                <td>延迟时间</td>
                <td> {{.detail.delay}}</td>
                <td></td>
            </tr>
            <tr>
                <td>TTR</td>
                <td> {{.detail.TTR}}</td>
                <td></td>
            </tr>

            <tr>
                <td>内容</td>
                <td>{{.detail.body}}</td>
                <td></td>
            </tr>
            
            </tbody>
        </table>
        <input type="hidden" name="id" id="id" value="{{.detail.id}}">
    </div>


</div>
<script>
    layui.use(['form','element','layer','jquery'],function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var id = $("#id").val();
        var error_info = "{{.flash.error}}";
        if(error_info){
            layer.msg(error_info,{icon: 2,shade:0.3},function () {
                window.history.go(-1)
            })
            return;
        }
        var task_name = "{{.task.TaskName}}";
        $('.layui-btn-container button').on('click',function () {
            var event = $(this).attr('lay-filter');

            if (event==='edit'){
                var status =" {{.task.Status}}";
                if(status==1){
                    layer.msg("运行状态无法编辑任务，请先暂停任务");
                    return;
                }
                window.parent.openTab("/task/edit?id="+id,task_name+' 编辑',"admin_task_edit-"+id,'fa-edit');
            }else if(event==='log'){
                window.parent.openTab("/tasklog/list?task_id="+id,task_name+'日志',"admin_log-"+id,'');
            }else if(event==='copy'){
                window.parent.openTab("/task/copy?id="+id,task_name+' 复制',"admin_task_copy-"+id,'fa-copy');
            }else if(event==="del"){
                var status =" {{.task.Status}}";
                if(status==1){
                    layer.msg("运行状态无法删除任务，请先暂停任务");
                    return;
                }

                layer.confirm("确认要删除这条任务吗？", {icon: 3, title:'提示'}, function(index){
                    layer.load();
                    $.post('/task/ajaxdel', {id:id}, function (out) {

                        if (out.status == 0) {
                            layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                                window.parent.deleteCurrentTab();
                            })
                        } else {
                            layer.msg(out.message);
                            return
                        }
                    }, "json");

                    setTimeout(function(){
                        layer.closeAll('loading');
                    }, 2000);

                    layer.close(index);
                });

            }else if (event==='run'){
                layer.confirm("测试执行任务，注意不要超时，请确认执行", {icon: 3, title:'提示'}, function(index){
                    layer.load();
                    $.post('/task/ajaxrun', {id:id}, function (out) {
                        if (out.status == 0) {
                            layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                                window.parent.openTab("/tasklog/list?task_id="+id,task_name+' 日志',"admin_task_log-"+id,'');

                            })
                        } else {
                            layer.msg(out.message)
                            return
                        }
                    }, "json");
                    setTimeout(function(){
                        layer.closeAll('loading');
                    }, 2000);
                    layer.close(index);
                });
            }else if (event==='audit' || event==='start' || event==='pause' || event==="nopass"){
                $.post('/task/ajax'+event, {id:id}, function (out) {
                    if (out.status == 0) {
                        layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                            window.location.reload()
                        })
                    } else {
                        layer.msg(out.message)
                        return
                    }
                }, "json");
                return
            }else{
                layer.msg("操作不存在")
            }
        })


        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();
    });
</script>


{{/*<script>*/}}

    {{/*layui.use(['table','form','element'], function(){*/}}
        {{/*var table = layui.table;*/}}
        {{/*var form = layui.form;*/}}
        {{/*var element = layui.element;*/}}

    {{/*});*/}}

{{/*</script>*/}}


</body>
</html>